/****************
  Hook up a shift register controlled LED Matrix to the ADAFruite GFX library.

  I would recommend using something like the HT16K33 or HT1632C
  controller if you can get one. If not, an appropriate shift register
  can do the job, but will require the MCU handle the multiplexing.
  
  This particular library is designed for driving a bicolor matrix
  using three 8-bit shift registers (the 74HC595, for instance) in
  series: Common closest to the Arduino, then Red, then Green. Connect
  them to the LED matrix so that data A-Q from each shift register
  drives row 1-8 or col 1-8 of the appropriate color or common.
  
  Note that this defaults to work with a common anode display, partly
  because the HT16K33 is built for common cathode, and requires
  conversion to work with common anode (and I'd be interested in
  hearing how to do that). However, it can be used with common cathode
  by calling matrix.common(CATHODE) after matrix.begin() and before
  matrix.writeDisplay().
*******/

#if (ARDUINO >= 100)
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <Adafruit_GFX.h>

#define LED_OFF		0
#define LED_RED 	1
#define LED_GREEN	2
#define LED_YELLOW	(LED_RED|LED_GREEN)

#define ANODE		0
#define CATHODE		1

class MWM_74595 : public Adafruit_GFX {
 public:
  MWM_74595() ;
  void begin(uint8_t dataPin_, uint8_t clockPin_, uint8_t latchPin_) ;

  // Emulating the ADAFruint bicolor matrix.
  void drawPixel(int16_t x, int16_t y, uint16_t color) ;
  void clear(void) ;
  void writeDisplay(void) ;

  // Hook to change the display time for rows, in microseconds.
  void commDelay(long newDelay) ;

  // Hook to set display for common anode/cathode
  // Cathode code is untested as yet.
  void common(uint8_t type) ;

 private:
  bool anode ;

  // Display buffer
  uint8_t redBuffer[8], greenBuffer[8] ;
} ;
